package cn.dnui_zll731.dnuifood_731zlll.controller;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.dnui_zll731.dnuifood_731zlll.Adapter.FoodListAdapter;
import cn.dnui_zll731.dnuifood_731zlll.R;
import cn.dnui_zll731.dnuifood_731zlll.bean.FoodBean;
import cn.dnui_zll731.dnuifood_731zlll.listener.RetrofitListener;
import cn.dnui_zll731.dnuifood_731zlll.model.ShopModel;

public class soucuoActivity extends BaseActivity implements RetrofitListener<List<FoodBean>> {
    private RecyclerView recyclerView;
    private TextView btn,ss_fanhui;
    private EditText textKuang;
    @Override
    protected int initlayout() {
        return R.layout.activity_sousuo;
    }
    @Override
    void initViews() {
        btn = findViewById(R.id.ss_btn);
        ss_fanhui = findViewById(R.id.ss_fanhui);
        textKuang = findViewById(R.id.ss_shurulan);
        recyclerView=findViewById(R.id.ss_rv1);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(
                this,
                LinearLayoutManager.VERTICAL,
                false
        );//布局效果---垂直布局
        recyclerView.setLayoutManager(linearLayoutManager);//设置效果
        recyclerView.setItemAnimator(new DefaultItemAnimator());//设置动画效果
    }

    @Override
    void initEvents() {
        ss_fanhui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        btn.setOnClickListener(new View.OnClickListener() {//搜索
            @Override
            public void onClick(View view) {
                jieguoye(textKuang.getText().toString().trim());
            }
        });
    }

    @Override
    void initData() {

    }
    private void jieguoye(String str){
        ShopModel shopModel = new ShopModel();
        shopModel.getFoodBySearch(str,this);
    }
    @Override
    public void onSuccess(List<FoodBean> object, int flag) {
        FoodListAdapter adapter = new FoodListAdapter(this,object,R.layout.food_item,"","");
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFalure() {
        showToast("网络错误");
    }
}
